package cn.sciento.boot.transfer.app.service.impl;

import cn.sciento.boot.transfer.app.service.ProducerEventArchService;
import cn.sciento.boot.transfer.domain.entity.ProducerEvent;
import cn.sciento.boot.transfer.domain.entity.ProducerEventArch;
import cn.sciento.boot.transfer.domain.repository.ProducerEventArchRepository;
import cn.sciento.boot.transfer.domain.repository.ProducerEventRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProducerEventArchServiceImpl implements ProducerEventArchService {
  @Autowired
  private ProducerEventRepository producerEventRepository;
  
  @Autowired
  private ProducerEventArchRepository producerEventArchRepository;
  
  @Transactional(rollbackFor = {Exception.class})
  public ProducerEventArch addProducerEventArch(ProducerEvent producerEvent) {
    this.producerEventRepository.deleteByPrimaryKey(producerEvent.getEventId());
    ProducerEventArch producerEventArch = ProducerEventArch.createInstance(producerEvent);
    producerEventArch.setProcessStatus("S");
    this.producerEventArchRepository.insertSelective(producerEventArch);
    return producerEventArch;
  }
}
